package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.setMchAllConfigBean;
import com.ymatou.iapi.godmch.service.setMchAllConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_config;
import com.ymttest.database.model.godmch.mch_configExample;
import com.ymttest.database.sqlwapper.godmch.mch_configWapper;
import com.ymttest.utils.TestDataManager;
/**
*设置商户配置信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setMchAllConfig{
	private static setMchAllConfigBean bean;
	private static setMchAllConfigCall call;
	private mch_configWapper mchconfigWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置商户配置信息");
	}

	@Before
	public void caseUp() {
		bean=new setMchAllConfigBean();
		call=new setMchAllConfigCall();
		mchconfigWapper=new mch_configWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private Map<String,Object> initMap(String priceTitle,String shoppingNotice)
	{

		Map<String,Object> map=new HashMap();
		map.put("waterMark", true);
		map.put("agentWaterMark", true);
		map.put("mchSideBuy",1);
		map.put("marketPriceEnabled", true);
		map.put("marketPriceTitle", priceTitle);
		map.put("overseasAddressEnabled", true);
		map.put("productPicAutoFill", true);
		map.put("supportHpCNY", true);
		map.put("wechatDomestic", true);
		map.put("dutyFreeDomestic", true);
		map.put("mchInfoEnabled", true);
		map.put("shoppingNotice", shoppingNotice);
		map.put("regTerm", true);
		map.put("buyerServiceCharge", true);
		map.put("offlineCollection", true);
		map.put("optionalIdCard", true);
		return map;
	}
	private void check_verify(String priceTitle,String shoppingNotice) throws InterruptedException
	{
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
		//校验表
		mch_configExample example=new mch_configExample();
        example.createCriteria().andMchIdEqualTo(bean.getMchId());
        mch_config mchconfig=mchconfigWapper.selectByExample(example).get(0);
		Logger.verifyEquals(true, mchconfig.getWaterMark(), "验证数据库中WaterMark字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getAgentWaterMark(), "验证数据库中agentWaterMark字段的值是否正确");
		
		Logger.verifyEquals(1, mchconfig.getMchSideBuy(), "验证数据库中MchSideBuy字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getMarketPriceEnabled(), "验证数据库中marketPriceEnabled字段的值是否正确");
		Logger.verifyEquals(priceTitle, mchconfig.getMarketPriceTitle(), "验证数据库中marketPriceTitle字段的值是否正确");
		
		Logger.verifyEquals(true, mchconfig.getOverseasAddressEnabled(), "验证数据库中overseasAddressEnabled字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getProductPicAutoFill(), "验证数据库中productPicAutoFill字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getSupportHpCNY(), "验证数据库中supportHpCNY字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getWechatDomestic(), "验证数据库中wechatDomestic字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getDutyFreeDomestic(), "验证数据库中dutyFreeDomestic字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getMchInfoEnabled(), "验证数据库中mchInfoEnabled字段的值是否正确");
		Logger.verifyEquals(shoppingNotice, mchconfig.getShoppingNotice(), "验证数据库中shoppingNotice字段的值是否正确");
		
		Logger.verifyEquals(true, mchconfig.getRegTerm(), "验证数据库中regTerm字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getBuyerServiceCharge(), "验证数据库中buyerServiceCharge字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getOfflineCollection(), "验证数据库中offlineCollection字段的值是否正确");
		Logger.verifyEquals(true, mchconfig.getOptionalIdCard(), "验证数据库中optionalIdCard字段的值是否正确");
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setMchAllConfig_001() {
		Logger.start(true,"设置商户配置信息-全都设置-返回成功");
		try {
			int mchId=GodmchManageCallService.CreateSellerMch();
	        String priceTitle="市场价显示标题_"+TestDataManager.getRandomNum(5);
	        String shoppingNotice="商品购买须知图片url"+TestDataManager.getRandomIntNum(5);
			Map<String,Object> map=initMap(priceTitle,shoppingNotice);
			bean.setMchId(mchId);
			bean.setconfigMap(map);
			call.setData(bean);
			call.callService();			
			check_verify( priceTitle, shoppingNotice);
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setMchAllConfig_002() {
		Logger.start(true,"设置商户配置信息-mchId为空-返回失败");
		try {
			int mchId=GodmchManageCallService.CreateSellerMch();
	        String priceTitle="市场价显示标题_"+TestDataManager.getRandomNum(5);
	        String shoppingNotice="商品购买须知图片url"+TestDataManager.getRandomIntNum(5);
			Map<String,Object> map=initMap(priceTitle,shoppingNotice);
			
		//	bean.setMchId(mchId);
			bean.setconfigMap(map);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setMchAllConfig_003() {
		Logger.start(true,"设置商户配置信息-mchId不存在,就新增一条-返回成功");
		try {
			int mchId=GodmchManageCallService.CreateSellerMch();
	        String priceTitle="市场价显示标题_"+TestDataManager.getRandomNum(5);
	        String shoppingNotice="商品购买须知图片url"+TestDataManager.getRandomIntNum(5);
			Map<String,Object> map=initMap(priceTitle,shoppingNotice);
			
			bean.setMchId(mchId+111);
			bean.setconfigMap(map);
			call.setData(bean);
			call.callService();			

			check_verify( priceTitle, shoppingNotice);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setMchAllConfig_004() {
		Logger.start(true,"设置商户配置信息-configMap为空-返回失败");
		try {
			int mchId=GodmchManageCallService.CreateSellerMch();
	        String priceTitle="市场价显示标题_"+TestDataManager.getRandomNum(5);
	        String shoppingNotice="商品购买须知图片url"+TestDataManager.getRandomIntNum(5);
			//Map<String,Object> map=initMap(priceTitle,shoppingNotice);
			
			bean.setMchId(mchId);
		//	bean.setconfigMap(map);
			call.setData(bean);
			call.callService();			
			//Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");	
		//	check_verify( priceTitle, shoppingNotice);	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}